#!/usr/bin/python3

import json
yes_key=["yes", "YES", "Y", "y"]
exit_key = ["exit", "q", "Q", "", " "]

def get_stored_usename():
    filename = "username.json"
    try:
        with open(filename) as f_obj:
            username = json.load(f_obj)
            #print(username)
    except FileNotFoundError:
            return None
    else:
        return username

def get_new_username():
    username = input("what's your name?\n")
    if username in exit_key:
        return None
    filename = "username.json"
    with open(filename,"w") as f_obj:
        json.dump(username, f_obj)
    return username

def greet_user():
    username = get_stored_usename()
    if username:
        resp = input(f"The '{username}' is your name?\n")
        if resp in yes_key:
            print(f"welcome back,{username}!")
        else:
            username = get_new_username()
            print(f"We'll remember you when you come back, {username}!")
    else:
        username = get_new_username()
        if username == None:
            return None
        print(f"We'll remember you when you come back, {username}!")


greet_user()
